package com.doit.doitdata.rule

import org.apache.spark.sql.SparkSession
import redis.clients.jedis.Jedis

/**
  * Created by hunter.coder 涛哥  
  * 2019/4/8 17:22
  * 交流qq:657270652
  * Version: 1.0
  * 更多学习资料：https://blog.csdn.net/coderblack/
  * Description: app描述信息字典知识库构建代码
  **/
object AppInfoRuleConstructor {

  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder()
      .master("local[*]")
      .appName(BizRuleConstructor.getClass.getSimpleName)
      .getOrCreate()

    import spark.implicits._


    // 加载数据：
    val ds1 = spark.read.textFile("G:\\sharkdata\\appdict")


    ds1.map(line=>{

      val fields = line.split("\t",-1)

      val appId = fields(4)
      val appName = fields(1)
      val appDesc = fields(5)
      (appId,appName,appDesc)

    }).foreachPartition(part=>{
      // 建redis连接
      val jedis = new Jedis("c701",6379)
      jedis.select(3)

      part.foreach(tp=>{
        jedis.set(tp._1,tp._2+"\001"+tp._3)
      })

      jedis.close()
    })

    spark.close()

  }

}
